<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/7/1
 * Time: 10:06
 */

include("check.php");
include("check2.php");
include_once("../function.php");
include_once("../class/email_class.php");
include_once("../class/system_class.php");
include_once("../class/ulevel_class.php");
date_default_timezone_set("PRC");
header("Content-Type: text/html;charset=utf-8");
session_start();
	$us=getMemberbyID($_SESSION['ID']);
	$UserTel=$us['usertel'];
	$BankName=$us['bankname'];
	$BankCard=$us['bankcard'];
	$BankUserName=$us['bankusername'];
	$BankAddress=$us['bankaddress'];
	$zhifubao=$us['zhifubao'];
	$caifutong=$us['caifutong'];
	$mey=$us['mey'];
	$pv=$us['pv'];
	$bdid=$us['bdid'];
	$bdname=$us['bdname'];
	$_system=new system_class();
	$system=$_system->system_information(1);
	$time=unserialize($system['txtime']);

	$ulevel=new ulevel_class();
	$_iul=$ulevel->getulevelbyulevel($us['ulevel']);
if ($_POST['submit']){
    $startdate=date("Y-m-d 00:00:00");
    $enddate=date("Y-m-d 23:59:59");
    $sql="select * from guamai where  uid={$us['id']} and tdate BETWEEN '{$startdate}' and '{$enddate}'";
    $query=mysql_query($sql);
    $num=mysql_num_rows($query);
  //  $ishk=ishk($us['usertel']);
    $us=getMemberbyID($_SESSION['ID']);
    if($us['fenghao']==1){
        echo "<script language=javascript>alert('你已被封号,不能进行此操作.');window.location.href='?'</script>";
    }else if($us['ispay']==3){
        echo "<script language=javascript>alert('你尚未回填完成,不能进行此操作.');window.location.href='?'</script>";
    } else if($num>0){
        echo "<script language=javascript>alert('挂卖中,不能进行此操作.');window.location.href='?'</script>";
    } else{
        $date = date("w");
        $hi = (int)date("Hi");
        $time1 = (int)date("Hi", strtotime($time[1]));
        $time2 = (int)date("Hi", strtotime($time[2]));
        $uid = $_SESSION['ID'];
        $jine = $_POST['jine'];
    if ( $us['pv']>= $us['sgb']){
        $cha = $_iul['yl11'] - $us['zfmey'] - $jine;
        if ($cha< 0) {
            $chae = $us['zfmey'] + $jine - $_iul['yl11'];
            $chamey = $jine - $chae;
            $jine = $chamey;
        }
        if ($jine > 0) {
            $tixian['uid'] = $uid;
            $tixian['nickname'] = $_SESSION['nickname'];
            $tixian['username'] = $us['username'];
            $tixian['usertel'] = $_POST['UserTel'];
            $tixian['tdate'] = now();
            $tixian['txlx'] = $txlx;
            $tixian['jine'] = $jine;
            $tixian['shouxu'] = $system['danjia'];
            $member['pv'] = $pv - $jine;
            $member['zfmey'] = $member['zfmey'] + $jine;
            add_insert_cl('guamai', $tixian);
            edit_update_cl('member', $member, $uid);
            $_email = new email_class();
            $email = $_email->getemail();
            if ($email['isstart'] == 1) {
                if ($email['txtzhy'] == 1){
                    $title = "提现申请通知";
                    $content = "尊敬的用户您好,您于" . now() . "向公司提现：" . $jine . "元,如不是您本人操作,请立即联系公司管理员.";
                    $_email->sendemail($us['useremail'], $us['nickname'], $title, $content);
                }
                if ($email['txtzadmin'] == 1) {
                    $title = "会员提现申请";
                    $content = "管理员您好,会员" . $us['nickname'] . "于" . now() . "向公司提现：" . $jine . "元";
                    $_email->sendemail($email['emailuser'], $email['emailname'], $title, $content);
                }
            }
            echo "<script language=javascript>alert('挂卖操作成功,请耐心等待.\\n本次挂卖金额:" . $jine . "');window.location.href='?'</script>";
        } else {
            echo "<script language=javascript>alert('当前挂卖已封顶，请升级');window.location.href='?'</script>";
        }


    } else {
        echo "<script language=javascript>alert('您的余额不足,挂卖失败');window.location.href='?'</script>";
    }


}

}
if($_GET['ID']){
    $id=$_GET['ID'];
    $iszt=$_GET['iszt'];
    $sql="select * from guamai where id=".$id;
    $row=getOne($sql);
    if($iszt==1){
        echo "<script language=javascript>alert('已卖出，不能撤销');window.location.href='?'</script>";
    }else{
        $member['pv'] =  $us['pv']+ $row['jine'];
        $member['zfmey'] = $us['zfmey'] -  $row['jine'];
        edit_update_cl('member', $member, $us['id']);
        edit_delete_cl('guamai',$id);
    }
}
$arr=array("","星期一","星期二","星期三","星期四","星期五","星期六","星期天")
?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <link href="css/table.css" rel="stylesheet" type="text/css">
    <link rel="stylesheet" type="text/css" href="css/style.css" />
    <title>奖金提现</title>
    <script language="javascript">
        <!--
        function CheckForm(){
/*            Txlx=document.form1.txlx.value;
            UserTel=document.form1.UserTel.value;
            BankCard=document.form1.BankCard.value;
            BankUserName=document.form1.BankUserName.value;
            BankAddress=document.form1.BankAddress.value;*/
            jine=document.form1.jine.value;
            xiao=2.02;
            da=3.69;
            if(jine.length == 0){
                alert("温馨提示:\n请输入挂卖金额.");
                document.form1.jine.focus();
                return false;
            }
            if(xiao > <?=$system['danjia']?> ){
                alert("温馨提示:\n当前价格不能挂卖.");
                document.form1.jine.focus();
                return false;
            }
            if(da < <?=$system['danjia']?> ){
                alert("温馨提示:\n当前价格不能挂卖.");
                document.form1.jine.focus();
                return false;
            }
            if( 1 ><?=$us['pv']-$us['sgb']?>){
                alert("温馨提示:\n当前为最低持有量，不能挂卖.");
                document.form1.jine.focus();
                return false;
            }

            if(jine > <?=($us['pv']-$us['sgb'])*$system['aixinjijin']/100?>){
                alert("温馨提示:\n最低持有量为<?=$us['sgb']?>积分挂卖只能挂卖<?=$us['pv']-$us['sgb']?>的<?=$system['aixinjijin']?>%");
                document.form1.jine.focus();
                return false;
            }
            return true;
        }

        function checknum(ob){

            var reg=/^[1-9]{1,}\d*$/;
            if(!reg.test(ob.value)){
                ob.value='';

            }
        }
        function showlist() {

            UserTel=document.form1.txlx.value;

            if (UserTel == "1") {
                document.getElementById('zt1').style.display = "";
                document.getElementById('zt2').style.display = "none";
            }
            else if (UserTel == "2") {
                document.getElementById('zt1').style.display = "none";
                document.getElementById('zt2').style.display = "";
            }
        }
        -->
    </script>
</head>
<body>
<form name="form1" method="post" action="?" onSubmit="return CheckForm();">
    <table  width="100%" cellpadding="3" cellspacing="1" border="0" align="center" class="table1">
        <tr style="display:none;">
            <td colspan="2" align="center">提现时间：<?php echo $arr[$time[0]]." ".$time[1]."-".$time[2];?></td>
        </tr>

        <tr id="zt2">
            <td width="46%" height="22" align="right">积分：</td>
            <td width="54%" align="left"><?=$pv?></td>
        </tr>


        <tr>
            <td height="22" align="right">卖出额度：</td>
            <td align="left"><input name="jine" type="text" id="jine" size="10" maxlength="10" onfocus="if(this.value==0)this.value='';" onblur="if(this.value==0)this.value='';" onkeyup="checknum(this);"/>
            </td>
        </tr>
    </table>
    <table align="center">
        <tr>
            <td><input name="submit" id="submit" type="submit" class="button_green" value="挂 卖"></td>
        </tr>
    </table>
    <br>
    <table width="100%" cellpadding="3" cellspacing="1" border="0" align="center" class="table1">
        <tr>
            <td height="20" colspan="14" align="center">挂 卖 记 录</td>
        </tr>
        <tr>
            <td align="center">会员编号</td>
            <td align="center">会员姓名</td>
            <td align="center">挂卖金额</td>
            <td align="center">当前价格</td>
<!--
            <td align="center">开户银行</td>
            <td align="center">开户帐号</td>
            <td align="center">开户姓名</td>
            <td align="center">开户地址</td>
            <td align="center">提现类型</td>-->
            <td align="center">挂卖状态</td>
            <td align="center">挂卖时间</td>
            <td align="center">操作</td>
<!--            <td align="center">服务中心</td>-->
        </tr>
        <?php
        $pagesize = 10; //设置每页记录数
        $sql = "SELECT * FROM `guamai` WHERE uid=".$_SESSION['ID']." ";
        if($query = mysql_query($sql)){
            $sum = mysql_num_rows($query); //计算总记录数
        }else{
            $sum=0;
        }
        if($sum % $pagesize == 0) //计算总页数
            $total = (int)($sum/$pagesize);
        else
            $total = (int)($sum/$pagesize) + 1;
        if (isset($_GET['page'])) //获得页码
        {
            $p = (int)$_GET['page'];
        }
        else
        {
            $p = 1;
        }
        if ($p>$total){
            $p=$total;
        }
        $start = $pagesize * ($p - 1); //计算起始记录
        $sql = "SELECT * FROM `guamai` WHERE uid=".$_SESSION['ID']." order by id desc limit ".$start.",".$pagesize;
        if($query = mysql_query($sql)){
            while ($row=mysql_fetch_array($query)){
                ?>
                <tr>
                    <td align="center"><?=$row['nickname']?></td>
                    <td align="center"><?=$row['username']?></td>
                    <td align="center"><?=$row['jine']?></td>
                    <td align="center"><?=$row['shouxu']?></td>
                    <!--        <td align="center"><?/*=$row['shouxu']*/?></td>
        <td align="center"><?/*=$row['glf']*/?></td>
        <td align="center"><?/*=$row['yingshi']*/?></td>-->
<!--                    <td align="center"><?/*=number_format($row['jine'],2) */?></td>-->
     <!--               <td align="center"><?/*=$row['bankname']*/?></td>
                    <td align="center"><?/*=$row['bankcard']*/?></td>
                    <td align="center"><?/*=$row['bankusername']*/?></td>
                    <td align="center"><?/*=$row['bankaddress']*/?></td>
                    <td align="center"><?php /*if ($row['txlx']==1){*/?>奖金<?php /*}else{*/?> 积分<?php /*}*/?></td>-->
                    <td align="center"><?php if ($row['isgrant']==1){?><font color="#2e8b57">已卖出</font><?php }elseif($row['isgrant']==0){ ?> <font color="#FF0000">挂卖中</font><?php }elseif($row['isgrant']==2){ ?><font color="#FF0000">未通过</font><?php }?></td>
                    <td align="center"><?=$row['tdate']?></td>
                    <td align="center"><input type="button" name="button" value="撤销" class="button_green" onclick="window.location.href='?ID=<?=$row['id']?>&iszt=<?=$row['isgrant']?>'"></td>
  <!--                  <td align="center"><?/*=$row['bdname']*/?></td>-->
                </tr>
                <?php
            }
        }
        ?>
    </table>
    <table width="100%" border="0" class="ziti">
        <tr>
            <td align="left">&nbsp;</td>
            <td align="right"><?php echo fenye($p,$pagesize,$sum,$total,$cx)?></td>
        </tr>
    </table>
</form>
</body>
</html>